#ifndef CMDLINEOPTIONDEFINITION_H_JM_20121220
#define CMDLINEOPTIONDEFINITION_H_JM_20121220

#include <string>
#include <vector>
#include <functional>

namespace jmlib {

	class CmdLineOptionDefinition {
	public:
		typedef std::function<bool(const std::string&)> ValueFilter;

		enum ValuePresence { NONE, ONE_REQUIRED, ONE_OPTIONAL,  MULTI_REQUIRED, 
			MULTI_OPTIONAL};

		CmdLineOptionDefinition(const std::string& name, 
			ValuePresence valuePresence) 
			: valuePresence_(valuePresence) {
				addAlias(name);
				resetFilter();
		}

		CmdLineOptionDefinition& addAlias(const std::string& alias) {
			aliases_.push_back(alias);
			return *this;
		}

		bool operator==(const std::string& alias) const {
			for (size_t i = 0; i < aliases_.size(); ++i) {
				if (aliases_[i] == alias) return true;
			}
			return false;
		}

		ValuePresence getValuePresence() const { return valuePresence_; }
		void setValuePresence(ValuePresence valuePresence) { 
			valuePresence_ = valuePresence; 
		}

		void setValueFilter(ValueFilter filter) {
			valueFilter_ = filter;
		}

		void resetFilter() {
			setValueFilter([](const std::string& x){ return true; });
		}

		ValueFilter getValueFilter() { return valueFilter_; }

	private:
		ValuePresence valuePresence_;
		std::vector<std::string> aliases_;
		ValueFilter valueFilter_;
	};
} // namespace jmlib

#endif
